import { DataProvider } from "../../../../../fl/data/DataProvider";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { Language } from "../../../../../extend/language/Language";
import { AssignGuildWarehouseExVo } from "./vo/AssignGuildWarehouseExVo";
import { EGuildAssignType } from "../../../../../Message/Game/EGuildAssignType";
import { EGuildPosition } from "../../../../../Message/Game/EGuildPosition";
import { EPrictUnit } from "../../../../../Message/Public/EPrictUnit";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SGuildPlayerAttendanceVo } from "./vo/SGuildPlayerAttendanceVo";
import { ArrayUtil } from "../../../../../com/gengine/utils/ArrayUtil";
import { MultiTakeOutMoneyWindow } from "./MultiTakeOutMoneyWindow";
import { ObjCreate } from "../../common/ObjCreate";
import { ScrollPolicy } from "../../../../../fl/controls/ScrollPolicy";
import { MultiAllocationItemRenderer } from "./itemRenderer/MultiAllocationItemRenderer";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTileList } from "../../../../../com/mui/controls/GTileList";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class MultiAllocationView
    
    export  class MultiAllocationView /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._memberData = [];
            this.init();
            return;
        }

        public onCleanHandler(arg1: Object /* flash.events.Event */=null): void
        {
            this.goldOutText = 0;
            this.coinOutText = 0;
            this._memberData = [];
            this.memberMumText = this._memberData.length;
            this._memberList.dataProvider = new DataProvider(this._memberData);
            if (this._multiTakeOutMoneyWindow && !this._multiTakeOutMoneyWindow.isHide) 
            {
                this._multiTakeOutMoneyWindow.hide();
            }
            return;
        }

        /* internal  */onInputMoneyHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!Cache.instance.guild.isCanManageWarehouse()) 
            {
                MsgManager.showRollTipsMsg(Language.getString(27973));
                return;
            }
            this.multiTakeOutMoneyWindow.memberSum = this._memberList.dataProvider.length;
            this.multiTakeOutMoneyWindow.storageGold = this._storageGold;
            this.multiTakeOutMoneyWindow.storageCoin = this._storageCoin;
            this.multiTakeOutMoneyWindow.responFun = this.setMoney;
            this.multiTakeOutMoneyWindow.show();
            return;
        }

        /* internal  */setMoney(arg1: int, arg2: int): void
        {
            if (arg1 > 0) 
            {
                this.goldOutText = arg1;
            }
            else if (arg2 > 0) 
            {
                this.coinOutText = arg2;
            }
            return;
        }

        /* internal  */set goldOutText(arg1: int)
        {
            this._goldOutText.text = arg1.toString();
            return;
        }

        /* internal  */get goldOutText(): int
        {
            if (this._goldOutText.text == "") 
            {
                return 0;
            }
            return int(this._goldOutText.text);
        }

        /* internal  */set coinOutText(arg1: int)
        {
            this._coinOutText.text = arg1.toString();
            return;
        }

        /* internal  */get coinOutText(): int
        {
            if (this._coinOutText.text == "") 
            {
                return 0;
            }
            return int(this._coinOutText.text);
        }

        /* internal  */onConfirmHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            if (!Cache.instance.guild.isCanManageWarehouse()) 
            {
                MsgManager.showRollTipsMsg(Language.getString(27973));
                return;
            }
            if (this._memberData.length <= 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(27974));
                return;
            }
            if (this.coinOutText == 0 && this.goldOutText > 0 && this.goldOutText < 10) 
            {
                MsgManager.showRollTipsMsg(Language.getString(27985));
                return;
            }
            if (this.goldOutText == 0 && this.coinOutText > 0 && this.coinOutText < 5000) 
            {
                MsgManager.showRollTipsMsg(Language.getString(27986));
                return;
            }
            if (!(this.coinOutText == 0) && !(this.goldOutText == 0) && (this.goldOutText < 10 || this.coinOutText < 5000)) 
            {
                if (this.goldOutText < 10) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(27985));
                }
                if (this.coinOutText < 5000) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(27986));
                }
                return;
            }
            if (this.coinOutText == 0 && this.goldOutText == 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(27985));
                MsgManager.showRollTipsMsg(Language.getString(27986));
                return;
            }
            if (this._memberData.length > 0 && (this.goldOutText > 0 || this.coinOutText > 0)) 
            {
                loc1 = new AssignGuildWarehouseExVo();
                loc1.type = EGuildAssignType.convert(EGuildAssignType._EGuildAssignBatch);
                var loc3=0;
                var loc4=this._memberData;
                for(loc2 of loc4) 
                {
                    if (loc2.itemData.position == EGuildPosition._EGuildLeader) 
                    {
                        MsgManager.showRollTipsMsg(Language.getString(27984));
                        return;
                    }
                    loc1.toPlayerIds.push(loc2.itemData.miniPlayer.entityId.id);
                }
                loc1.moneyMap[EPrictUnit._EPriceUnitGold] = this.goldOutText;
                loc1.moneyMap[EPrictUnit._EPriceUnitCoin] = this.coinOutText;
                Dispatcher.dispatchEvent(new DataEvent(EventName.ConfirmAssignGuildWarehouseEx, {"vo": loc1}));
            }
            return;
        }

        /* internal  */onCancelItem(arg1: DataEvent): void
        {
            var loc1=arg1.data as SGuildPlayerAttendanceVo;
            if (loc1) 
            {
                ArrayUtil.removeItem(this._memberData, loc1);
                this._memberList.dataProvider = new DataProvider(this._memberData);
                this._memberList.drawNow();
                this.memberMumText = this._memberData.length;
            }
            return;
        }

        /* internal  */get multiTakeOutMoneyWindow(): MultiTakeOutMoneyWindow
        {
            if (this._multiTakeOutMoneyWindow == null) 
            {
                this._multiTakeOutMoneyWindow = new MultiTakeOutMoneyWindow();
            }
            return this._multiTakeOutMoneyWindow;
        }

        /* internal  */setStorageMoneyAmount(arg1: int, arg2: int): void
        {
            this._storageGoldText.text = arg1.toString();
            this._storageCoinText.text = arg2.toString();
            return;
        }

        /* internal  */set memberMumText(arg1: int)
        {
            this._memberMumText.htmlText = Language.getStringByParam(27962, arg1);
            return;
        }

        public addItem(arg1: SGuildPlayerAttendanceVo): void
        {
            this._memberData.push(arg1);
            this._memberList.dataProvider = new DataProvider(this._memberData);
            this._memberList.drawNow();
            this.memberMumText = this._memberData.length;
            return;
        }

        public setGuildWarehouseMoney(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            if (arg1) 
            {
                this._storageGold = arg1[EPrictUnit._EPriceUnitGold];
                this._storageCoin = arg1[EPrictUnit._EPriceUnitCoin];
            }
            this.setStorageMoneyAmount(this._storageGold, this._storageCoin);
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ObjCreate.createBg(5, -6, 257, 210, this);
            this._memberList = ObjCreate.createTileList(5, 0, 255, 200, this);
            this._memberList.scrollPolicy = ScrollPolicy.AUTO;
            this._memberList.columnWidth = 254;
            this._memberList.rowHeight = 35;
            this._memberList.setStyle("cellRenderer", MultiAllocationItemRenderer);
            var loc2=ObjCreate.createSpBannerAndBg(5, 207, 257, 163, "", this);
            var loc3=ObjCreate.createTextField(Language.getString(27981), 90, 209, 160, 30, this, new GTextFormat(FontUtil.lishuName, 20, 16187136));
            this._memberMumText = ObjCreate.createGTextField(Language.getStringByParam(27962, 0), 10, 240, 180, 20, this, GlobalStyle.textFormat2, true);
            var loc4=GlobalClass.getBitmap("Yuanbao");
            ObjCreate.setObjAttri(loc4, 15, 260, -1, -1, this);
            this._goldOutText = ObjCreate.createGTextField("0", 35, 260, 180, 20, this, GlobalStyle.textFormat2);
            var loc5=GlobalClass.getBitmap("Tongqian");
            ObjCreate.setObjAttri(loc5, 150, 260, -1, -1, this);
            this._coinOutText = ObjCreate.createGTextField("0", 170, 260, 180, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createBg(5, 280, 260, 2, this, ImagesConst.SplitLine);
            var loc6=ObjCreate.createGTextField(Language.getString(27963), 10, 285, 180, 20, this, GlobalStyle.textFormat2, true);
            var loc7=GlobalClass.getBitmap("Yuanbao");
            ObjCreate.setObjAttri(loc7, 15, 305, -1, -1, this);
            this._storageGoldText = ObjCreate.createGTextField("", 35, 305, 180, 20, this, GlobalStyle.textFormat2);
            var loc8=GlobalClass.getBitmap("Tongqian");
            ObjCreate.setObjAttri(loc8, 150, 305, -1, -1, this);
            this._storageCoinText = ObjCreate.createGTextField("", 170, 305, 180, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createBg(5, 325, 260, 2, this, ImagesConst.SplitLine);
            var loc9;
            (loc9 = ObjCreate.createGButton(Language.getString(27964), 45, 334, 72, 28, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onInputMoneyHandler);
            var loc10;
            (loc10 = ObjCreate.createGButton(Language.getString(27966), 155, 334, 72, 28, this)).addEventListener(flash.events.MouseEvent.CLICK, this.onConfirmHandler);
            Dispatcher.addEventListener(EventName.MultiAllocationCancelItem, this.onCancelItem);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onCleanHandler);
            return;
        }

        /* internal */ /* var */_memberList: GTileList;

        /* internal */ /* var */_memberMumText: GTextFiled;

        /* internal */ /* var */_goldOutText: GTextFiled;

        /* internal */ /* var */_coinOutText: GTextFiled;

        /* internal */ /* var */_storageGoldText: GTextFiled;

        /* internal */ /* var */_storageCoinText: GTextFiled;

        /* internal */ /* var */_storageGold: int;

        /* internal */ /* var */_storageCoin: int;

        /* internal */ /* var */_multiTakeOutMoneyWindow: MultiTakeOutMoneyWindow;

        /* internal */ /* var */_memberData: Array<any>;
    }
